#pragma once
#include <string>
#include <windows.h>
#include "shpa3api.h"
#include "DeviceStatePool.h"
#include "TinySanhuiLibDefine.h"

using namespace DeviceStates;

class CDevice
{
public:
	friend class CDeviceState;
	CDevice(void);
	virtual ~CDevice(void);

	template<typename T>
	void changeState(const T& state)
	{
		CDeviceState* pState = g_DeviceStatePool.createState(state);
		if(pState == NULL)
		{
			return;
		}
		if(m_CurrentState!= NULL)
		{
			delete m_CurrentState;
			m_CurrentState = pState;
			return;
		}
		else
			m_CurrentState = pState;

		m_CurrentState->deviceHandle = this;

		return;
		
	}
	virtual CDeviceState* getState(void);
	virtual void setDeviceID(std::string id);
	virtual std::string getDeviceID(void);
	virtual void setChannelID(int id);
	virtual int getChannelID(void);
	virtual int CardCallBackProc(WORD wEvent, DWORD dwParam) = 0;
	virtual void ProcessReceivedMsg(CTinyMsg &inMsg,CTinyMsg &OutMsg) = 0;
	void SetBoardSN(std::string sn)
	{
		m_BoardSN = sn;
	}
	void SetBoardType(std::string type)
	{
		m_BoardType = type;
	}
	std::string GetBoardSN()
	{
		return m_BoardSN;
	}
	std::string GetBoardType()
	{
		return m_BoardType;
	}
	bool pickup();
protected:
	std::string m_BoardSN;
	std::string m_BoardType;
public:
	int m_ChannelID;
	std::string m_DeviceID;
	CDeviceState* m_CurrentState;
};
